package pattern.active;

import pattern.command.SuicideCommand;

import java.util.LinkedList;

/**
 * 自杀主动对象模式
 *
 * @author sun.ye
 * @since 2020-07-14 18:30
 */
public class SadActiveObject {

    LinkedList<SuicideCommand> commands = new LinkedList<>();

    public void addCommand(SuicideCommand command){
        commands.add(command);
    }

    public void run(){
        while (!commands.isEmpty()){
            SuicideCommand command = commands.getFirst();
            commands.removeFirst();
            command.suicide();
        }
    }
}